package com.briup.estore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.briup.estore.dao.ShopDao;
import com.briup.estore.entity.ShopEntity;
import com.briup.estore.entity.vo.RecommendShopVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.briup.estore.common.utils.PageUtils;

import com.briup.estore.dao.RecommendShopDao;
import com.briup.estore.entity.RecommendShopEntity;
import com.briup.estore.service.RecommendShopService;


@Service("recommendShopService")
public class RecommendShopServiceImpl extends ServiceImpl<RecommendShopDao, RecommendShopEntity> implements RecommendShopService {

    @Autowired
    private  RecommendShopDao recommendShopDao;

    @Autowired
    private ShopDao shopDao;
    @Override
    public List<ShopEntity> recommendShopsByUser(Long userId) {
        List<ShopEntity> list = recommendShopDao.findRecommendShopByUser(userId).stream().map(i->  i.getShop()).limit(10).collect(Collectors.toList());
        return list.isEmpty()? shopDao.selectList(new QueryWrapper<ShopEntity>().orderByDesc("sales_volume")).stream().limit(10).collect(Collectors.toList()):list;

    }
}